var adCarousel = [
    {
        "url": "",
        "image": "ajax/ad.jpg",
        "title": "每满500减100"
    },
    {
        "url": "",
        "image": "ajax/ad2.jpg",
        "title": "手机专享"
    }
];
seajs.use(['zepto', 'channel-responsive', 'iscroll', 'pagenation', 'filter-bar', 'responsive-image', 'touch-slider'], function ($, channelResponsive, iScroll, pagenation, filterbar, responsiveImage, touchSlider) {
    var callback;
    if ($('#startCity').text() != '定位中...') {
        callback = function () {
            $('.loading').hide();
            $('#content').css('opacity', 1);
        };
    } else {
        callback = function () {
        };
    }
    tuniu_common.distance.show($);
    channelResponsive.init({cityCode: cityCode, onResponseImageLoaded: callback}, {getCurrentCityInfoAjax: $('#getCurrentCityInfoAjax').val(), querySuggestionAjax: $('#querySuggestionAjax').val()}, function (data) {
    });
    var tour30 = {url: window.location.href, app: false, init: function () {
        this.fillTopSlide(adCarousel);
        this.app = tuniu_common.isApp();
        if (this.app) {
            $('#footer').hide();
        }
        if (niurenFlag == 1) {
            var arr = this.url.split('-');
            $('#ruler ul li').on('click', function () {
                var li = $(this);
                var pageNum = li.children('a').text();
                arr[arr.length - 2] = pageNum;
                var newUrl = arr.join('-');
                li.children('a').attr('href', newUrl);
                window.location.href = newUrl;
            });
        }
        this.bindEvent();
        this.initAppFunc();
        pagenation.init(totalPageNum, currentPageNum);
        var filterbarData = {poiId: poiId, catId: catId, channel: channel, niurenFlag: niurenFlag, cityLetter: cityLetter, sortKey: sortKey, catId: catId, minDays: minDays || 0, maxDays: maxDays || 0, minPrice: minPrice || 0, maxPrice: maxPrice || 0, minDate: minDate || 0, maxDate: maxDate || 0, pageNum: currentPageNum, channelType: channelType, playType: playType || 0, channelLocalList: channelList};
        var filterbarUrl = {getCurrentUrlAjax: $('#getCurrentUrlAjax').val(), getFilterListAjax: $("#getFilterListAjax").val(), getAllFilterListAjax: $("#getAllFilterListAjax").val(), };
        filterbar.init(filterbarData, filterbarUrl);
        this.dealSomething();
        this.setNoProductHeight();
    }, fillTopSlide: function (t) {
        var a = this;
        var i = $("#slider").html("");
        var n = $("#pagenavi").html("");
        var o = 0;
        for (var o in t) {
            var l = $("<li><a href='" + t[o].url + "'><img src='" + t[o].image + "' alt='" + t[o].title + "'/></a></li>");
            if (o == 0) {
                l.css("display", "block")
            }
            i.append(l);
            var s = $("<a href='javascript:;'></a>");
            if (o == 0) {
                s.addClass("active")
            }
            n.append(s);
            o++
        }
        setTimeout(function () {
            a.initSlide.call(a)
        }, 500)
    }, initSlide: function () {
        var e = 0, a = document.getElementById("pagenavi").getElementsByTagName("a");
        for (var i = 0; i < a.length; i++) {
            (function (e) {
                a[i].onclick = function () {
                    n.slide(e);
                    return false
                }
            })(i)
        }
        var n = new touchSlider({id: "slider", speed: 600, timeout: 6e3, before: function (t) {
            a[e].className = "";
            e = t;
            a[e].className = "active"
        }})
    }, bindEvent: function () {
        var self = this;
        window.onresize = function (e) {
            self.dealSomething();
        };
        window.onorientationchange = function (e) {
            self.dealSomething();
            if (/.*version\/([\w.]+).*(safari).*/.test(navigator.userAgent.toLowerCase())) {
                var scrollTop = $('body').scrollTop();
                if (scrollTop > 0) {
                    window.scrollTo(0, 0);
                    $('#header').css('top', 0);
                    $('#sidebar').css('top', 0);
                }
            }
        };
    }, initAppFunc: function () {
        if (this.app) {
            tuniu_common.loadTuniuAppBridge(function () {
                $('a[data-appurl]').on('click', function () {
                    if ($(this).attr('data-appurl')) {
                        window.location.href = $(this).attr('data-appurl');
                        return false;
                    }
                });
            });
        }
    }, dealSomething: function () {
        var width = document.documentElement.clientWidth;
        if (width >= 768 && width < 1024) {
            var li = $('.product-list>ul>li');
            var length = li.length;
            if (length % 3 == 1) {
                li.eq(length - 1).css('border-bottom', 'none');
            } else if (length % 3 == 2) {
                li.eq(length - 1).css('border-bottom', 'none');
                li.eq(length - 2).css('border-bottom', 'none');
            } else if (length % 3 == 0) {
                li.eq(length - 1).css('border-bottom', 'none');
                li.eq(length - 2).css('border-bottom', 'none');
                li.eq(length - 3).css('border-bottom', 'none');
            }
        } else if (width >= 1024) {
            var li = $('.product-list>ul>li');
            var length = li.length;
            if (length % 4 == 1) {
                li.eq(length - 1).css('border-bottom', 'none');
            } else if (length % 4 == 2) {
                li.eq(length - 1).css('border-bottom', 'none');
                li.eq(length - 2).css('border-bottom', 'none');
            } else if (length % 4 == 3) {
                li.eq(length - 1).css('border-bottom', 'none');
                li.eq(length - 2).css('border-bottom', 'none');
                li.eq(length - 3).css('border-bottom', 'none');
            } else if (length % 4 == 0) {
                li.eq(length - 1).css('border-bottom', 'none');
                li.eq(length - 2).css('border-bottom', 'none');
                li.eq(length - 3).css('border-bottom', 'none');
                li.eq(length - 4).css('border-bottom', 'none');
            }
        }
    }, setNoProductHeight: function () {
        var height = document.documentElement.clientHeight;
        var headerHeight = $('#header').height();
        var screenbarHeight = $('.screenbar').height();
        var footerHeight = $('#footer').height();
        var heightx = height - headerHeight - screenbarHeight - footerHeight;
        var noProductHeight = $('.no-product .img').height() + $('.no-product p').height() * 2;
        var paddingx = (heightx - noProductHeight) / 3;
        $('.no-product').height(heightx - paddingx);
        $('.no-product').css('padding-top', paddingx);
    }};
    tour30.init();
});